package com.ybwh.springboot2.common.mybatis.plugin.tablerouter;

import org.apache.commons.lang3.StringUtils;

/**
 * @author fanbeibei
 * @version 1.2.0
 * @date 2022/2/19 20:12
 */
public class TableRouteHelper {


    private TableRouteHelper() {
    }


    /**
     * @author fanbeibei
     * @version 1.2.0
     * @date 2022/2/19 19:49
     */
    private static class TableSuffixHolder {
        private static ThreadLocal<String> TABLE_SUFFIX = new ThreadLocal<>();


        public static String get() {
            return TABLE_SUFFIX.get();
        }


        public static void set(String tableSuffix) {
            TABLE_SUFFIX.set(tableSuffix);
        }


    }


    public static final String DEFAULT_TABLE_SUFFIX = "dongfeng";

    public static void setTableSuffix(String tableSuffix) {
        TableSuffixHolder.set(tableSuffix);
    }


    public static String getTableSuffix() {
        String ts = TableSuffixHolder.get();

        if (StringUtils.isBlank(ts)) {
            return DEFAULT_TABLE_SUFFIX;
        }

        return ts;
    }

}
